from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage, SKU
from meiduo_admin.serializers.skus import SKUImageSerializer, SKUSimpleSerializer


class SKUImageViewSet(ModelViewSet):
    # 权限判断
    permission_classes = [IsAdminUser]
    # 指定router动态生成路由时，提取参数的正则表达式
    lokup_value_regex = '\d+'
    # 指定试图所用的查询集
    queryset = SKUImage.objects.all()
    # 指定试图所用的序列化器
    serializer_class = SKUImageSerializer


class SKUSimpleView(ListAPIView):
    # 权限判断
    permission_classes = [IsAdminUser]
    # 指定试图所用的查询集
    queryset = SKU.objects.all()
    # 指定试图说用的序列化器
    serializer_class = SKUSimpleSerializer

    # 不分页设置
    pagination_class = None

